package com.example;

import org.apache.camel.builder.RouteBuilder;

/**
 * A simple Camel route that triggers from a timer and calls a bean and prints to system out.
 * <p/>
 * Use <tt>@Component</tt> to make Camel auto detect this route when starting.
 */
//@Component
public class MySpringBootRouter extends RouteBuilder {

    @Override
    public void configure() {
        from("timer:hello?period={{timer.period}}").routeId("hello")
            .transform().method("myBean", "saySomething")
            .filter(simple("${body} contains 'foo'"))
                .to("log:foo")
            .end()
            .to("stream:out");
        from("mqtt:myMqtt?subscribeTopicName=myTopic&host=tcp://myMqttBroker:1883")
                .process(exchange -> {
                    // 获取消息体
                    String messageBody = exchange.getIn().getBody(String.class);
                    // 对消息进行处理
                    String modifiedBody = "Processed: " + messageBody;
                    // 设置修改后的消息体
                    exchange.getIn().setBody(modifiedBody);
                })
                .to("http4://myHttpService/api/data").autoStartup(true);
    }




}
